package pl.wroc.uni.ii.evolution.sampleimplementation;

import pl.wroc.uni.ii.evolution.engine.individuals.EvBinaryVectorIndividual;
import pl.wroc.uni.ii.evolution.engine.operators.general.display.EvRealtimeToPrintStreamStatistics;
import pl.wroc.uni.ii.evolution.engine.operators.general.selections.EvTournamentSelection;
import pl.wroc.uni.ii.evolution.engine.prototype.EvTask;
import pl.wroc.uni.ii.evolution.engine.samplealgorithms.EvMIMIC;
import pl.wroc.uni.ii.evolution.engine.terminationconditions.EvMaxIteration;
import pl.wroc.uni.ii.evolution.objectivefunctions.EvKDeceptiveOneMax;
import pl.wroc.uni.ii.evolution.solutionspaces.EvBinaryVectorSpace;


public class EvMIMICExample {

  public static void main(String[] args) {
    
    EvKDeceptiveOneMax objective_function = new EvKDeceptiveOneMax(4);
    
    EvMIMIC alg = new EvMIMIC(4000, new EvTournamentSelection<EvBinaryVectorIndividual>(16, 4));
    alg.setSolutionSpace(new EvBinaryVectorSpace(objective_function, 60));
    alg.setObjectiveFunction(objective_function );
    alg.setTerminationCondition(new EvMaxIteration<EvBinaryVectorIndividual>(17));
    alg.addOperator(new EvRealtimeToPrintStreamStatistics<EvBinaryVectorIndividual>(System.out));
    
    EvTask task = new EvTask();
    task.setAlgorithm(alg);
    
    long cur_time = System.currentTimeMillis();
    task.run();
    long after_time = System.currentTimeMillis();
    System.out.println("RUN TIME: " + ((after_time - cur_time)/1000) + " sec");
    System.out.print("best: ");
    task.printBestResult();
  }
}
